class monsterBulletManager {
    constructor() {
        this.data = {
            //ID:tBullet
        };
        this.bulletID = 1000;
        this.bulletLayer = null;
    }
    setLayer(layer) {
        this.bulletLayer = layer;
    }
    doLaunch(node) {
        //发射子弹
        //加载资源
        let tBullet = cc.instantiate(g_Res.getRes("bullet", "bullet6"));
        this.bulletLayer.addChild(tBullet);
        //获取node坐标
        tBullet.setPosition(node.x, node.y);
        //登记子弹
        tBullet.ID = this.bulletID++;
        tBullet.speed = 5;
        tBullet.life = 3;//子弹寿命
        tBullet.attack = node.attack;//子弹伤害
        //出生时就应该设定移动方向
        let role = game.getRole();
        let direction = role.position.sub(tBullet.position);//获取方向向量
        let angle = Math.atan2(direction.y, direction.x);
        tBullet.angle = angle;
        this.data[tBullet.ID] = tBullet;
    }
    onCollisionEnter(role, bullet) {
        let hurt = bullet.attack;
        //造成伤害
        game.role.script.onHurt(hurt);
        //然后销毁
        delete this.data[bullet.ID];
        bullet.destroy();
    }
    update(dt) {
        let tData = {};
        for (let id in this.data) {
            tBullet = this.data[id];
            let angle = tBullet.angle;
            let speed = tBullet.speed;
            tBullet.x += speed * Math.cos(angle);
            tBullet.y += speed * Math.sin(angle);
            tBullet.life -= dt;
            if (tBullet.life <= 0) {
                tBullet.destroy();
            } else {
                tData[id] = tBullet;
            }
        }
        this.data = tData;
    };
}
window.g_MstBullet = new monsterBulletManager(); 